package com.loongtech.bi.manager.player;

import com.loongtech.bi.entity.player.EntityNewDevice;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NewDeviceManager extends TypeNewManager<EntityNewDevice> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 根据开始结束时间查询所有新增设备数据
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityNewDevice> getNewDevicesByDate(Date dateStart, Date dateEnd) {
		return findByQuery("from EntityNewDevice where 1=1 and day>=:dayStart and day<=:dayEnd order by day ", "dayStart", dateStart, "dayEnd", dateEnd);
	}

    /**
     * 根据开始结束时间查询所有新增设备数据
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public List<EntityNewDevice> getNewDevicesByDate2(Date dateStart, Date dateEnd) {
        return findByQuery("from EntityNewDevice where 1=1 and day>=:dayStart and day<=:dayEnd and serverid='0' order by day ", "dayStart", dateStart, "dayEnd", dateEnd);
    }

    public List<Object[]> getNewUserByAllKind(Date dateStart, Date dateEnd,String queryPlatform, String queryChannel, String queryServer) {
        return getNewDeviceByAllKind(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
    }

	/**
	 * 根据开始结束时间查询某个维度的数值
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getNewDeviceByAllKind(Date dateStart, Date dateEnd,String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select date_format(day,'%Y-%m-%d'),new_device from EntityNewDevice where day>=:dayStart and day<=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' and new_device is not null group by day order by day desc", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据platformid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getNewDeviceGroupByPlatform(Date dateStart, Date dateEnd) {
		return findByQuery("select platformid,sum(new_device) from EntityNewDevice where day>=:dayStart and day<=:dayEnd and platformid != '0' and new_device is not null group by platformid", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据channelid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getNewDeviceGroupByChannel(Date dateStart, Date dateEnd) {
		return findByQuery("select channelid,sum(new_device) from EntityNewDevice where day>=:dayStart and day<=:dayEnd and channelid != '0' and new_device is not null group by channelid", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据serverid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getNewDeviceGroupByServer(Date dateStart, Date dateEnd) {
		return findByQuery("select serverid,sum(new_device) from EntityNewDevice where day>=:dayStart and day<=:dayEnd and serverid != '0' and new_device is not null group by serverid", "dayStart", dateStart, "dayEnd", dateEnd);
	}
}
